package org.ramesh.OneToManyTesting;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class AppSaver {
	
	
	public static void main(String args[]) {
		
		/*
		Category category = new Category();
		category.setName("Books");
		
		Product product = new Product();
		product.setName("Medicen");
		product.setPrice(1234);
		product.setDiscription("NTR University");
		product.setCategory(category);
		
		Product product2 = new Product();
		product2.setName("Science");
		product2.setPrice(5432);
		product2.setDiscription("OU...");
		product2.setCategory(category);
		
		Set<Product> products = new HashSet<Product>();
		products.add(product);
		products.add(product2);
		
		category.setProduct(products);
		
		SessionFactory factory = new Configuration().configure().buildSessionFactory();
		Session session = factory.openSession();
		Transaction tx = session.beginTransaction();
		
		session.save(category);
		
		session.getTransaction().commit();
		session.close();
		
		*/
		
		
		SessionFactory factory = new Configuration().configure().buildSessionFactory();
		Session session = factory.openSession();
		Transaction tx = session.beginTransaction();
		
		Category cat = (Category) session.get(Category.class, 1L);
		
		System.out.println(cat.getProduct());
		
		session.getTransaction().commit();
		session.close();
	}

}
